package com.endlessblue.visa.config;

import java.io.IOException;
import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.Ssl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;

@Component
@PropertySource("classpath:business.properties")
public class CommonConfig {
	
	/**
	 * 空字符串处理
	 * @return
	 */
	@Bean
	public ObjectMapper objectMapper () {
		ObjectMapper objectMapper = new ObjectMapper();
		SerializerProvider serializerProvider = objectMapper.getSerializerProvider();
		serializerProvider.setNullValueSerializer(
				new JsonSerializer<Object>() {  
		            @Override  
		            public void serialize(Object value, JsonGenerator jgen,  
		                    SerializerProvider provider) throws IOException,  
		                    JsonProcessingException {  
		                jgen.writeString("");  
		            }  
        });
		objectMapper.setDateFormat(new SimpleDateFormat("yyyyMMddHHmmssSSS"));
		return objectMapper;
	}
	
	/*@Bean
	public EmbeddedServletContainerCustomizer containerCustomizer() {
	    return new EmbeddedServletContainerCustomizer() {
	        @Override
	        public void customize(ConfigurableEmbeddedServletContainer container) {
	            Ssl ssl = new Ssl();
	            //Server.jks中包含服务器私钥和证书
	            ssl.setKeyStore(storePath);
	            ssl.setKeyStorePassword(storePwd);
	            container.setSsl(ssl);
	            container.setPort(8443);
	        }
	    };
	}*/
}
